package com.example.orderassembly.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.orderassembly.service.IServiceOrderDetailService;
import com.woniu.cloud.common.exception.TicketException;
import com.woniuxy.api.ServiceOrderDetailApi;
import com.woniu.cloud.common.dto.Result;
import com.woniuxy.entity.ServiceOrderDetail;
import com.woniuxy.form.InsertServiceOrderDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务订单详情表 前端控制器
 * </p>
 *
 * @author yang
 * @since 2021-09-21
 */
@RestController
@Slf4j
@SuppressWarnings("ALL")
public class ServiceOrderDetailController implements ServiceOrderDetailApi {
    @Resource
    IServiceOrderDetailService serviceOrderDetailService;

    //todo 接口未完成

    @Override
    public Result insertServiceOrderDetail(InsertServiceOrderDetail insertServiceOrderDetail) {
        log.info("插入服务订单详情 insertServiceOrderDetail={}",insertServiceOrderDetail);
        if(null==insertServiceOrderDetail){
            log.info("参数错误");
//            return Result.fail("参数错误",null);
            throw  new TicketException("参数异常");
        }
        Boolean bool = serviceOrderDetailService.insertServiceOrderDetail(insertServiceOrderDetail);
        return bool?Result.success("新增成功",bool):Result.fail("新增失败",bool);
    }

    @Override
    public Result getServiceOrderDetailByPlatform(Integer indexPage) {
        return null;
    }

    @Override
    public Result getServiceOrderDetailByStore(Integer storeId, Integer indexPage) {
        return null;
    }

    @Override
    public Result getServiceOrderDetailByUser(Integer userId, Integer indexPage, Integer serviceOrderId) {
        return null;
    }

    @Override
    public Result updateServiceOrderDetailStatus(Integer serviceOrderDetailId, Integer statues) {
        return null;
    }

    @Override
    public Result getServiceOrderDetailByProductOrderId(Integer serviceOrderId){
        log.info("根据某个商品id 查询对应的 参数  服务订单id serviceOrderId={}",serviceOrderId);
        if(null==serviceOrderId){
            log.info("参数错误");
//            return Result.fail("参数错误",null);
            throw  new TicketException("参数异常");
        }
        List<ServiceOrderDetail> iPage = serviceOrderDetailService.getServiceOrderDetailByProductOrderId(serviceOrderId);
        return iPage.size()==0?Result.fail("查询失败",iPage):Result.success("成功",iPage);
    }

}

